%% Assignment 3; Precipitation
% 3.1	Rainfall undercatch
clear all;close all;


%% Define dataset and variables
data.gaugeHeight    = [0.00; 0.30; 1.52; 3.05; 4.57; 6.10];
data.windSpeed      = [0.00; 1.63; 2.71; 3.17; 3.44; 3.63];

g   = 9.81;     % Gravitational acceleration [m/s2]
d   = 2*10^-3;  % Diameter raindrop. note1 [m]
Cd  = 0.517;    % drag coefficient []
rhoA= 1.225;    % density air [kg/m3]
rhoW= 1000;     % Density rainwater [kg/m3]
D   = 0.20;     % Diameter raingauge [m]

%% 3.1.1 Plot data
figure(1);
plot(data.gaugeHeight,data.windSpeed);
xlabel('Gauge height [m]');
ylabel('Wind speed [m/s]');

%% 3.1.2 
vTer    = sqrt(4*g*d*((rhoW/rhoA)-1)/(3*Cd));   % terminal velocity [m/s]

%% 3.1.3
V       = sqrt(vTer^2+data.windSpeed.^2);   % total velocity [m/s]

%% 3.1.4
theta   = atand(vTer./data.windSpeed);      % angle of attack [deg]

%% 3.1.5
De      = D.*sind(theta);                   % effective diameter [m]
Ae      = .25*pi*De.^2;                     % effective catchment [m2]

%% 3.1.6
A       = .25*pi*D^2;                       % Area raingauge [m2]
I       = V.*Ae./A;                         % Intensity 
undercatch= I./I(1);                        % Undercatch [-]

figure(2);
plot(data.gaugeHeight,undercatch);
xlabel('Gauge height [m]');
ylabel('Undercatch [-]');

%% Notes
% 1
% USGS: minimal size raindrop is 0.4 mm. The maximum size is 4 mm, before
% it splits in two. http://ga.water.usgs.gov/edu/raindropsizes.html